<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/ssb/include/common-base.jsp"%>
  <title>文章内容编辑</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.all.js"> </script>
  <script type="text/javascript" src="${ctx}/js/ueditor/lang/zh-cn/zh-cn.js" ></script>
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/ssb/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/ssb/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">
        <div class="col-xs-12">
			<div class="box box-solid">
				<div class="box-header with-border">
					<h3 class="box-title">文章内容-<span id="span_cms_types">新增</span></h3> <button onclick="toBack()" class="btn btn-info btn-xs">返回</button>
				</div>
				<div class="box-body">
					<form class="form-horizontal addFormBody" role="form" id="addForm1" action="javascript:void(0)">
						<input type="hidden" class="formToken" id="addForm1_formToken" name="formToken" />
						<input type="hidden" name="pageName" value="ss-information"/>
						<input type="hidden" name="formName" value="addForm"/>
						<input type="hidden" name="ssInformation.w_infoId" data-name="ssInformation.infoId" value=""/>

						<table class="table table-bordered bordercolor">
							<tbody>
							<tr>
								<td class="active" align="right"><label
										class="form-control-static">分类：</label></td>
								<td>
									<div class="form-group w220"><select
											id="addForm1_ssInformation_infoClassify"
											name="ssInformation.infoClassify"
											class="form-control  clean"
											data-name="ssInformation.infoClassify"
											data-dict-code="dictItemList"
											data-dict-cate="informationType"
											data-type-tag="select" placeholder="必填项"
											data-bv-notempty="true"
											data-bv-notempty-message="不能为空" data-def="">
										<option value="">--请选择--</option>
									</select></div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right"><label
										class="form-control-static">封面：</label></td>
								<td>
									<div class="form-group">
										<div file-box="true" name="ssInformation.infoCover"
											 data-type-tag="uploadImg" data-file-type="image/*" data-upload-folder="cms">
											<img data-name="ssInformation.infoCover" file-img="true" src="/ssb/images/plateform/def.jpg" style="width:120px;height:80px;">
											<label file-btn="true"
												   onclick="addUploadFileNew(this);"
												   for="uploadFileInputNew"
												   class="btn btn-warning">选择图片</label> <input
												file-input="true"  data-name="ssInformation.infoCover"
												name="ssInformation.infoCover" type="hidden"
												class="clean"> <a file-a="true" href="#"
																  style="display:none;"
																  target="_bank"></a> <label
												file-msg="true"
												style="color:red;display:none;"></label>
										</div>
									</div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right"><label
										class="form-control-static">标题：</label></td>
								<td>
									<div class="form-group"><input
											name="ssInformation.infoTitle"
											class="form-control clean" maxlength="100"
											data-name="ssInformation.infoTitle"
											placeholder="必填项" data-bv-notempty="true"
											data-bv-notempty-message="不能为空"></div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right"><label
										class="form-control-static">是否启用：</label></td>
								<td>
									<div class="form-group">
										<div class="form-control-static" id="addForm1_ssInformation_infoStatus"
											 name="ssInformation.infoStatus" data-temp-obj="ssInformation.infoStatus"
											 data-dict-code="dictItemList" data-dict-cate="yesOrNo"
											 data-colmun="" data-condition="" data-type-tag="radio" data-def=""
											 data-name="ssInformation.infoStatus">[radio]
										</div>

									</div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right"><label
										class="form-control-static">内容详情：</label></td>
								<td>
									<div class="form-group">
										<textarea class="form-control clean hidden" rows="2" maxlength="1000" name="ssInformation.infoContent"
												  data-name="ssInformation.infoContent" ></textarea>
										<textarea id="content" style="width:0%;height:0px;display:none;" name="content"></textarea>
										<script id="editorId" type="text/plain"  style="width:100%;height:290px;"></script>
									</div>
								</td>
							</tr>
							</tbody>
						</table>
					</form>
				</div>
				<div class="box-footer">
					<div class="col-sm-12">
						<div class="box-footer text-center">
							<button class="btn btn-success pull-left" type="button" onclick="toBack();"> 取消 </button>
							<button class="btn btn-danger pull-right" type="button" onclick="submitForm1('addForm1','');" data-temp-event="addForm1_hidden"> 提 交 </button>
						</div>
					</div>
				</div>
			</div>
        </div>
      </div>

<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "cms-list";
var myPage,dataListId,searchFormId;
var infoId = '${param.infoId}';
/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();
var ue = UE.getEditor("editorId");//初始化对象
$(function () {
	var formId ="#addForm1";
	setValidate(formId);//定义add表单验证属性
	mytools.cleanValidate(formId);//清空上次校验规则提示
	localStorage.setItem("file_directory",sysName+'/cms');

	if(!strUtil.isNull(infoId)){
		console.log('infoId',infoId);
		//修改
		$('#span_cms_types').text('修改');
		$(formId).find("input[name='formName']").val('editForm');
		toLoad();
	}
 });
function toLoad(){
	$.ajax({
		type:"get",
		url:common_info_url,dataType:"json",
		data: {'pageName':'ss-information','formName':'searchForm','ssInformation.w_infoId':infoId},
		success: function(myData){
			console.log('myData.info',myData);
			FormUtil.loadView('ssInformation', myData['ssInformation'],"#addForm1");
			ue.setContent(myData['ssInformation'].infoContent);
		}
	});
}
function toBack() {
	window.location.href=page_admin+"/cms/cms-list";
}
//提交表单数据
function submitForm1(formId,tabId){
	//校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过就返回
		return;
	}
	var textContent =UE.getEditor("editorId").getContent();
	$("#"+formId).find("textarea[name='ssInformation.infoContent']").val(textContent);

	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
			, function(){
				var result = submitForm(formId,tabId);
				if(result){
					layer.alert("操作成功！");
					window.location.href=page_admin+"/cms/cms-list";
				}
			});
}
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:'post',
		url:common_submit_url,
		data:$("#"+formId).serialize(),
		async:false,
		dataType:'json',
		success: function(myData){
			console.log(myData);
			if(myData.flag=="T"){
				result = myData;
			}else{
				setToken();
				layer.alert(myData.msg);
			}
			layer.close(index_load);
		},
		error: function (e) {
			layer.close(index_load);
		}
	});
	return result;
}
//设置token
function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('.formToken').val(myData);
	  	}
	});	
}


/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
<!-- foot start -->
<%@include file="/common/ssb/foot.jsp" %>
<!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>














